using System;
using System.Data;
using System.Xml;
using System.Runtime.Serialization;
using System.Collections;
using System.Collections.Generic;
using Widgetsphere.Core.Logging;
using Widgetsphere.Core.Exceptions;
using Widgetsphere.Core.DataAccess;
using ACME.Northwind.Business;
using ACME.Northwind.Business.Rules;
using Widgetsphere.Core.WinUI;
using ACME.Northwind.Domain.Objects;
using System.ComponentModel;
using Widgetsphere.Core.EventArgs;
using ACME.Northwind.Business.Objects.Composites;
using System.IO;

namespace ACME.Northwind.Business.Objects
{
	/// <summary>
	/// Interface definition for the 'CustomerDemographic' entity
	/// </summary>
	public interface ICustomerDemographic : IPersistableBusinessObject, IAuditable, ICloneable
	{
		#region Properties

		/// <summary>
		/// The CustomerDesc field
		/// </summary>
		string CustomerDesc { get; set; }
		/// <summary>
		/// The CustomerTypeId field
		/// </summary>
		string CustomerTypeId { get; }

		#endregion

		#region Methods

		/// <summary>
		/// This event is called before persisting to the database.
		/// </summary>
		event EventHandler<BusinessObjectEventArgs> Validate;

		/// <summary>
		/// Removes this object from its parent collection. It will not be deleted from the database.
		/// </summary>
		void Remove();

		/// <summary>
		/// The primary key for this object
		/// </summary>
		new CustomerDemographicPrimaryKey PrimaryKey { get; }

		/// <summary>
		/// Persists this object to the database.
		/// </summary>
		new void Persist();

		/// <summary>
		/// Creates a clone of this object.
		/// </summary>
		new IBusinessObject Clone();

		#endregion

	}

	/// <summary>
	/// Class definition for the 'CustomerDemographic' entity
	/// </summary>
	[Serializable()]
	public partial class CustomerDemographic : BusinessObjectPersistableBase, IPersistableBusinessObject, ICustomerDemographic
	{
		#region Class Members

		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'CustomerDemographic' table.
		/// </summary>
		public enum FieldNameConstants
		{
			 /// <summary>
			 /// Field mapping for the 'CustomerTypeId' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CustomerTypeId' property")]
			CustomerTypeId,
			 /// <summary>
			 /// Field mapping for the 'CustomerDesc' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CustomerDesc' property")]
			CustomerDesc,
			 /// <summary>
			 /// Field mapping for the 'CreatedBy' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedBy' property")]
			CreatedBy,
			 /// <summary>
			 /// Field mapping for the 'CreatedDate' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedDate' property")]
			CreatedDate,
			 /// <summary>
			 /// Field mapping for the 'ModifiedBy' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedBy' property")]
			ModifiedBy,
			 /// <summary>
			 /// Field mapping for the 'ModifiedDate' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedDate' property")]
			ModifiedDate,
		}
		#endregion

		internal DomainCustomerDemographic wrappedClass;

		#endregion

		#region Constructors

		/// <summary>
		/// Creates a 'CustomerDemographic' object from a domain object
		/// </summary>
		internal CustomerDemographic(DomainCustomerDemographic classToWrap)
		{
			wrappedClass = classToWrap;
		}

		/// <summary>
		/// Creates a 'CustomerDemographic' object from a DataRowView
		/// </summary>
		internal CustomerDemographic(DataRowView drvToWrap)
		{
			wrappedClass = (DomainCustomerDemographic)drvToWrap.Row;
		}

		#endregion

		#region Events

		/// <summary>
		/// This event is raised before the 'CustomerDesc' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> CustomerDescChanging;

		/// <summary>
		/// This event is raised when the 'CustomerDesc' field is changed.
		/// </summary>
		public event EventHandler CustomerDescChanged;

		/// <summary>
		/// This event is raised before the 'CustomerTypeId' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> CustomerTypeIdChanging;

		/// <summary>
		/// This event is raised when the 'CustomerTypeId' field is changed.
		/// </summary>
		public event EventHandler CustomerTypeIdChanged;

		/// <summary>
		/// Raises the CustomerDescChanging event.
		/// </summary>
		protected virtual void OnCustomerDescChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.CustomerDescChanging != null)
				this.CustomerDescChanging(this, e);
		}

		/// <summary>
		/// Raises the CustomerDescChanged event.
		/// </summary>
		protected virtual void OnCustomerDescChanged(System.EventArgs e)
		{
			if (this.CustomerDescChanged != null)
				this.CustomerDescChanged(this, e);
		}

		/// <summary>
		/// Raises the CustomerTypeIdChanging event.
		/// </summary>
		protected virtual void OnCustomerTypeIdChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.CustomerTypeIdChanging != null)
				this.CustomerTypeIdChanging(this, e);
		}

		/// <summary>
		/// Raises the CustomerTypeIdChanged event.
		/// </summary>
		protected virtual void OnCustomerTypeIdChanged(System.EventArgs e)
		{
			if (this.CustomerTypeIdChanged != null)
				this.CustomerTypeIdChanged(this, e);
		}

		#endregion

		#region Properties

		/// <summary>
		/// The current state of this object.
		/// </summary>
		public Widgetsphere.Core.DataAccess.SubDomainBase.ItemStateConstants ItemState
		{
			get { return (Widgetsphere.Core.DataAccess.SubDomainBase.ItemStateConstants)int.Parse(wrappedClass.RowState.ToString("d")); }
		}

		/// <summary>
		/// Determines the type of collection that contains this object.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public Collections Container
		{
			get { return Collections.CustomerDemographicCollection; }
		}

		#region CreatedBy / ModifiedBy Section

		/// <summary>
		/// The audit field for the 'Modified By' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual string ModifiedBy
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.ModifiedByColumn];
				if (o == DBNull.Value) return null;
				else return (string)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.ModifiedByColumn] = value; }
		}

		/// <summary>
		/// The audit field for the 'Modified Date' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual DateTime? ModifiedDate
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.ModifiedDateColumn];
				if (o == DBNull.Value) return null;
				else return (DateTime)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.ModifiedDateColumn] = value; }
		}

		/// <summary>
		/// Sets 'ModifiedBy' column.
		/// </summary>
		public virtual void SetModifiedDate(DateTime newValue)
		{
			this.wrappedClass[this.wrappedClass.ParentCol.ModifiedDateColumn] = newValue;
		}

		/// <summary>
		/// The audit field for the 'Created By' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual string CreatedBy
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.CreatedByColumn];
				if (o == DBNull.Value) return null;
				else return (string)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.CreatedByColumn] = value; }
		}

		/// <summary>
		/// The audit field for the 'Created Date' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual DateTime? CreatedDate
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.CreatedDateColumn];
				if (o == DBNull.Value) return null;
				else return (DateTime)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.CreatedDateColumn] = value; }
		}

		/// <summary>
		/// Sets 'ModifiedBy' column.
		/// </summary>
		public virtual void SetCreatedDate(DateTime newValue)
		{
			this.wrappedClass[this.wrappedClass.ParentCol.CreatedDateColumn] = newValue;
		}

		[System.ComponentModel.Browsable(false)]
		internal virtual byte[] TimeStamp
		{
			get
			{
				 object o = this.wrappedClass[this.wrappedClass.ParentCol.TimeStampColumn];
				 return (byte[])o;
			}
			set { this.wrappedClass[this.wrappedClass.ParentCol.TimeStampColumn] = value; }
		}

		#endregion

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (((DataRow)this.WrappedClass).RowState != DataRowState.Detached); }
		}

		/// <summary>
		/// Returns the internal object that this object wraps
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		internal virtual object WrappedClass
		{
			get{ return wrappedClass; }
			set{ wrappedClass = (DomainCustomerDemographic)value; }
		}

		//WrappingClass Interface
		object IWrappingClass.WrappedClass
		{
			get { return this.WrappedClass; }
			set { this.WrappedClass = value; }
		}

		/// <summary>
		/// The primary key for this object
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual CustomerDemographicPrimaryKey PrimaryKey
		{
			get
			{
				try
				{
					return wrappedClass.PrimaryKey;
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: CustomerDesc
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string CustomerDesc
		{
			get
			{
				try { return wrappedClass.CustomerDesc; }
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.CustomerDesc))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "CustomerDemographic.CustomerDesc", GetMaxLength(FieldNameConstants.CustomerDesc)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnCustomerDescChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.CustomerDesc = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("CustomerDesc"));
						this.OnCustomerDescChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}

		}

		/// <summary>
		/// Property for table field: CustomerTypeID
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string CustomerTypeId
		{
			get
			{
				try { return wrappedClass.CustomerTypeId; }
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		internal virtual void ReleaseNonIdentifyingRelationships()
		{
			try
			{
				wrappedClass.ReleaseNonIdentifyingRelationships();
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		/// <summary>
		/// A list of related 'CustomerCustomerDemo' items
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual BusinessObjectList<CustomerCustomerDemo> CustomerCustomerDemoList
		{
			get
			{
				try
				{
					if (this.ParentCollection == null)
					{
						lock (this)
						{
							return wrappedClass.CustomerCustomerDemoList;
						}
					}
					else
					{
						lock (this.ParentCollection.SubDomain)
						{
							return wrappedClass.CustomerCustomerDemoList;
						}
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}


		#endregion

		#region Collection Operation Methods

		/// <summary>
		/// This event is called before persisting to the database.
		/// </summary>
		public event EventHandler<BusinessObjectEventArgs> Validate;

		/// <summary>
		/// This event is called before persisting to store.
		/// </summary>
		/// <param name="item"></param>
		protected internal void OnValidate(BusinessObjectEventArgs item)
		{
			if (this.Validate != null)
				this.Validate(this, item);
		}

		/// <summary>
		/// Persists this object to the database.
		/// </summary>
		public override void Persist()
		{
		  if (this.IsParented)
		  {
				this.OnValidate(new BusinessObjectEventArgs(this));
			  wrappedClass.Persist();
		  }
		  else
		    throw new Exception("This item is not part of a collection and cannot be persisted!");
		}

		/// <summary>
		/// Removes this object from its parent collection. It will not be deleted from the database.
		/// </summary>
		public void Remove()
		{
			try
			{
				if (this.ParentCollection == null)
				{
					lock (this)
					{
						wrappedClass.Remove();
					}
				}
				else
				{
					lock (this.ParentCollection.SubDomain)
					{
						wrappedClass.Remove();
					}
				}
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		/// <summary>
		/// Marks this object for deletion. The next call to the Persist method will delete it from the database.
		/// </summary>
		public void Delete()
		{
			try
			{
				if (this.ParentCollection == null)
				{
					lock (this)
					{
						wrappedClass.Delete();
					}
				}
				else
				{
					lock (this.ParentCollection.SubDomain)
					{
						wrappedClass.Delete();
					}
				}
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		#endregion

		#region Overrides

		/// <summary>
		/// Serves as a hash function for this particular type.
		/// </summary>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		/// <summary>
		/// Returns a value indicating whether the current object is equal to a specified object.
		/// </summary>
		public override bool Equals(object obj)
		{
			if (obj == null) return false;
			if (obj.GetType() == this.GetType())
			{
				if (this.wrappedClass.Equals(((CustomerDemographic)obj).wrappedClass))
					return true;
			}
			else if(obj.GetType() == this.PrimaryKey.GetType())
			{
			  if(this.PrimaryKey.Equals(obj))
			    return true;
			}
			else if (obj.GetType() == this.PrimaryKey.CustomerTypeId.GetType())
			{
				if (this.PrimaryKey.CustomerTypeId.Equals(obj))
					return true;
			}
			return false;
		}

		#endregion

		#region IBusinessObject ParentCollection

		/// <summary>
		/// This is a reference back to the generic collection that holds this object.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		IBusinessCollection IBusinessObject.ParentCollection
		{
			get { return this.ParentCollection; }
		}

		#endregion

		#region ParentCollection

		/// <summary>
		/// This is a reference back to the collection that holds this object.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public CustomerDemographicCollection ParentCollection
		{
			get { return new CustomerDemographicCollection(wrappedClass.ParentCol); }
		}

		#endregion

		#region GetDefault

		/// <summary>
		/// Gets the default value of one of this object's properties.
		/// </summary>
		public object GetDefault(FieldNameConstants field)
		{
			if(field == FieldNameConstants.CustomerDesc)
				return "";
			if(field == FieldNameConstants.CustomerTypeId)
				return "";

			return null;
		}

		object IBusinessObject.GetDefault(Enum field)
		{
			return this.GetDefault((FieldNameConstants)field);
		}

		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if(field == FieldNameConstants.CustomerTypeId)
				return this.CustomerTypeId;
			if(field == FieldNameConstants.CustomerDesc)
				return ((this.CustomerDesc == null) ? defaultValue : this.CustomerDesc);
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(FieldNameConstants field)
		{
			return this.GetInteger(field, int.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(FieldNameConstants field, int defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				int a;
				if (int.TryParse((string)o, out a))
					return a;
				else
					throw new InvalidCastException();
			}
			else
			{
				return (int)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(FieldNameConstants field)
		{
			return this.GetDouble(field, double.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(FieldNameConstants field, double defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				double a;
				if (double.TryParse((string)o, out a))
					return a;
				else
					throw new InvalidCastException();
			}
			else
			{
				return (double)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public DateTime GetDateTime(FieldNameConstants field)
		{
			return this.GetDateTime(field, DateTime.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public DateTime GetDateTime(FieldNameConstants field, DateTime defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				DateTime a;
				if (DateTime.TryParse((string)o, out a))
					return a;
				else
					throw new InvalidCastException();
			}
			else
			{
				return (DateTime)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(FieldNameConstants field)
		{
			return this.GetString(field, "");
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(FieldNameConstants field, string defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				return (string)o;
			}
			else
			{
				return o.ToString();
			}
		}

		#endregion

		#region SetValue

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		public void SetValue(FieldNameConstants field, object newValue)
		{
			SetValue(field, newValue, false);
		}

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		/// <param name="fixLength">Determines if the length should be truncated if too long. When false, an error will be raised if data is too large to be assigned to the field.</param>
		public void SetValue(FieldNameConstants field, object newValue, bool fixLength)
		{
			if (field == FieldNameConstants.CustomerTypeId)
			{
				throw new Exception("Field '" + field.ToString() + "' is a primary key and cannot be set!");
			}
			else if (field == FieldNameConstants.CustomerDesc)
			{
				if (newValue == null)
				{
					this.CustomerDesc = null;
				}
				else
				{
					string v = newValue.ToString();
					if (fixLength)
					{
						int fieldLength = GetFieldLength(FieldNameConstants.CustomerDesc);
						if (v.Length > fieldLength) v = v.Substring(0, fieldLength);
					}
					this.CustomerDesc = v;
				}
				return;
			}
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region GetFieldLength

		/// <summary>
		/// Determines the length of the specified field if it can be set.
		/// </summary>
		public int GetFieldLength(CustomerDemographic.FieldNameConstants field)
		{
			if(field == FieldNameConstants.CustomerTypeId) return 10;
			if(field == FieldNameConstants.CustomerDesc) return 16;
			//Catch all for all other data types
			return -1;
		}
		#endregion

		#region Clone

		/// <summary>
		/// Create a copy of this object.
		/// </summary>
		public virtual IBusinessObject Clone()
		{
			lock (this)
			{
				if (!this.IsParented) throw new Exception("The current item must be parented.");
				CustomerDemographic newItem = null;
				lock (this.ParentCollection.SubDomain)
				{
					newItem = new CustomerDemographic(this.ParentCollection.wrappedClass.NewItem());
				}
				this.FillClone(newItem);
				return newItem;
			}
		}

		/// <summary>
		/// Create a copy of this object.
		/// <param name="customertypeid">The customertypeid field</param>
		/// </summary>
		public virtual IBusinessObject Clone(string customertypeid)
		{
			lock (this)
			{
				if (!this.IsParented) throw new Exception("The current item must be parented.");
				CustomerDemographic newItem = null;
				lock (this.ParentCollection.wrappedClass.SubDomain)
				{
				newItem = new CustomerDemographic(this.ParentCollection.wrappedClass.NewItem(customertypeid));
				}
				this.FillClone(newItem);
				return newItem;
			}
		}

		private void FillClone(CustomerDemographic newItem)
		{
			lock (this)
			{
				lock (newItem)
				{
					newItem.CustomerDesc = this.CustomerDesc;
				}
			}
		}

		object ICloneable.Clone()
		{
			return this.Clone();
		}

		#endregion

		#region Helper Methods

		string IBusinessObject.GetFriendlyName(Enum field)
		{
			return "";
		}

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.CustomerDesc:
					return int.MaxValue;
				case FieldNameConstants.CustomerTypeId:
					return 10;
			}
			return 0;
		}

		int IBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		string IBusinessObject.GetMask(Enum field)
		{
			return "";
		}

		/// <summary>
		/// Select a single object from this collection by its primary key.
		/// </summary>
		public static CustomerDemographic SelectUsingPK(string customertypeid)
		{
			return SelectUsingPK(customertypeid, "");
		}

		/// <summary>
		/// Select a single object from this collection by its primary key.
		/// </summary>
		public static CustomerDemographic SelectUsingPK(string customertypeid, string modifier)
		{
			CustomerDemographicCollection customerdemographic = CustomerDemographicCollection.SelectUsingPK(customertypeid, modifier);
			if (customerdemographic.Count > 1) throw new Exception("CustomerDemographic primary key returned more than one value.");
			else if (customerdemographic.Count == 0) return null;
			else return customerdemographic[0];
		}

		#endregion

		#region IBusinessObject Members

		IPrimaryKey IBusinessObject.PrimaryKey
		{
			get { return this.PrimaryKey; }
		}

		object IBusinessObject.GetValue(Enum field)
		{
			return this.GetValue((FieldNameConstants)field);
		}

		object IBusinessObject.GetValue(Enum field, object defaultValue)
		{
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		double IBusinessObject.GetDouble(Enum field)
		{
			return this.GetDouble((FieldNameConstants)field);
		}

		double IBusinessObject.GetDouble(Enum field, double defaultValue)
		{
			return this.GetDouble((FieldNameConstants)field, defaultValue);
		}

		DateTime IBusinessObject.GetDateTime(Enum field)
		{
			return this.GetDateTime((FieldNameConstants)field);
		}

		DateTime IBusinessObject.GetDateTime(Enum field, DateTime defaultValue)
		{
			return this.GetDateTime((FieldNameConstants)field, defaultValue);
		}

		int IBusinessObject.GetInteger(Enum field)
		{
			return this.GetInteger((FieldNameConstants)field);
		}

		int IBusinessObject.GetInteger(Enum field, int defaultValue)
		{
			return this.GetInteger((FieldNameConstants)field, defaultValue);
		}

		string IBusinessObject.GetString(Enum field)
		{
			return this.GetString((FieldNameConstants)field);
		}

		string IBusinessObject.GetString(Enum field, string defaultValue)
		{
			return this.GetString((FieldNameConstants)field, defaultValue);
		}

		void IPersistableBusinessObject.SetValue(Enum field, object newValue)
		{
			this.SetValue((FieldNameConstants)field, newValue);
		}

		Enum IBusinessObject.Container
		{
			get { return this.Container; }
		}

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(IBusinessObject item)
		{
			if (item == null) return false;
			if (!(item is CustomerDemographic)) return false;
			CustomerDemographic o = item as CustomerDemographic;
			return (
				o.CustomerTypeId == this.CustomerTypeId &&
				o.CustomerDesc == this.CustomerDesc
				);
		}

		#endregion

		#region IAuditable Members

		string IAuditable.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		DateTime? IAuditable.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		bool IAuditable.IsCreateAuditImplemented
		{
			get { return true; }
		}

		bool IAuditable.IsModifyAuditImplemented
		{
			get { return true; }
		}

		bool IAuditable.IsTimestampAuditImplemented
		{
			get { return true; }
		}

		string IAuditable.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		DateTime? IAuditable.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		byte[] IAuditable.TimeStamp
		{
			get { return this.TimeStamp; }
		}

		#endregion

	}

}
